from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-03-03 14:02:33.014245
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 03, Mar, 2022
Time: 14:02:38
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.3562
Nobs: 584.000 HQIC: -48.7672
Log likelihood: 6948.72 FPE: 5.08985e-22
AIC: -49.0297 Det(Omega_mle): 4.36861e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.350951 0.067818 5.175 0.000
L1.Burgenland 0.108022 0.041193 2.622 0.009
L1.Kärnten -0.110569 0.021494 -5.144 0.000
L1.Niederösterreich 0.190938 0.086037 2.219 0.026
L1.Oberösterreich 0.124033 0.084952 1.460 0.144
L1.Salzburg 0.256696 0.043643 5.882 0.000
L1.Steiermark 0.036415 0.057637 0.632 0.528
L1.Tirol 0.101676 0.046514 2.186 0.029
L1.Vorarlberg -0.068352 0.041009 -1.667 0.096
L1.Wien 0.017267 0.075531 0.229 0.819
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.051831 0.146055 0.355 0.723
L1.Burgenland -0.037769 0.088715 -0.426 0.670
L1.Kärnten 0.041769 0.046291 0.902 0.367
L1.Niederösterreich -0.204919 0.185293 -1.106 0.269
L1.Oberösterreich 0.458429 0.182956 2.506 0.012
L1.Salzburg 0.282128 0.093991 3.002 0.003
L1.Steiermark 0.113985 0.124130 0.918 0.358
L1.Tirol 0.304608 0.100174 3.041 0.002
L1.Vorarlberg 0.026209 0.088318 0.297 0.767
L1.Wien -0.027140 0.162666 -0.167 0.867
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.200212 0.034644 5.779 0.000
L1.Burgenland 0.088824 0.021043 4.221 0.000
L1.Kärnten -0.007172 0.010980 -0.653 0.514
L1.Niederösterreich 0.239892 0.043951 5.458 0.000
L1.Oberösterreich 0.160702 0.043397 3.703 0.000
L1.Salzburg 0.039833 0.022295 1.787 0.074
L1.Steiermark 0.025954 0.029444 0.882 0.378
L1.Tirol 0.081850 0.023761 3.445 0.001
L1.Vorarlberg 0.053715 0.020949 2.564 0.010
L1.Wien 0.118234 0.038584 3.064 0.002
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.119812 0.034623 3.460 0.001
L1.Burgenland 0.042729 0.021030 2.032 0.042
L1.Kärnten -0.013050 0.010973 -1.189 0.234
L1.Niederösterreich 0.170482 0.043925 3.881 0.000
L1.Oberösterreich 0.337153 0.043371 7.774 0.000
L1.Salzburg 0.099777 0.022281 4.478 0.000
L1.Steiermark 0.110640 0.029426 3.760 0.000
L1.Tirol 0.089911 0.023747 3.786 0.000
L1.Vorarlberg 0.060557 0.020936 2.892 0.004
L1.Wien -0.018316 0.038561 -0.475 0.635
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.124704 0.065106 1.915 0.055
L1.Burgenland -0.044924 0.039546 -1.136 0.256
L1.Kärnten -0.045277 0.020635 -2.194 0.028
L1.Niederösterreich 0.136281 0.082597 1.650 0.099
L1.Oberösterreich 0.161725 0.081556 1.983 0.047
L1.Salzburg 0.285247 0.041898 6.808 0.000
L1.Steiermark 0.057243 0.055333 1.035 0.301
L1.Tirol 0.157139 0.044654 3.519 0.000
L1.Vorarlberg 0.096911 0.039369 2.462 0.014
L1.Wien 0.074007 0.072511 1.021 0.307
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.079214 0.050749 1.561 0.119
L1.Burgenland 0.024826 0.030825 0.805 0.421
L1.Kärnten 0.053319 0.016084 3.315 0.001
L1.Niederösterreich 0.188856 0.064383 2.933 0.003
L1.Oberösterreich 0.333424 0.063571 5.245 0.000
L1.Salzburg 0.033285 0.032659 1.019 0.308
L1.Steiermark 0.006553 0.043131 0.152 0.879
L1.Tirol 0.119193 0.034807 3.424 0.001
L1.Vorarlberg 0.065402 0.030688 2.131 0.033
L1.Wien 0.097762 0.056521 1.730 0.084
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.170941 0.061292 2.789 0.005
L1.Burgenland 0.005487 0.037229 0.147 0.883
L1.Kärnten -0.065859 0.019426 -3.390 0.001
L1.Niederösterreich -0.107206 0.077758 -1.379 0.168
L1.Oberösterreich 0.208354 0.076777 2.714 0.007
L1.Salzburg 0.053964 0.039443 1.368 0.171
L1.Steiermark 0.247689 0.052091 4.755 0.000
L1.Tirol 0.499571 0.042038 11.884 0.000
L1.Vorarlberg 0.064267 0.037062 1.734 0.083
L1.Wien -0.073983 0.068262 -1.084 0.278
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.161501 0.067992 2.375 0.018
L1.Burgenland -0.001912 0.041299 -0.046 0.963
L1.Kärnten 0.063007 0.021549 2.924 0.003
L1.Niederösterreich 0.166020 0.086258 1.925 0.054
L1.Oberösterreich -0.055877 0.085170 -0.656 0.512
L1.Salzburg 0.208451 0.043755 4.764 0.000
L1.Steiermark 0.138283 0.057786 2.393 0.017
L1.Tirol 0.055757 0.046634 1.196 0.232
L1.Vorarlberg 0.146841 0.041114 3.572 0.000
L1.Wien 0.121026 0.075725 1.598 0.110
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.392640 0.039928 9.834 0.000
L1.Burgenland -0.004351 0.024253 -0.179 0.858
L1.Kärnten -0.021128 0.012655 -1.670 0.095
L1.Niederösterreich 0.199679 0.050655 3.942 0.000
L1.Oberösterreich 0.230931 0.050016 4.617 0.000
L1.Salzburg 0.036817 0.025695 1.433 0.152
L1.Steiermark -0.016843 0.033934 -0.496 0.620
L1.Tirol 0.090540 0.027385 3.306 0.001
L1.Vorarlberg 0.050819 0.024144 2.105 0.035
L1.Wien 0.043658 0.044469 0.982 0.326
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036589 0.102649 0.168406 0.138351 0.094062 0.080794 0.032431 0.209089
Kärnten 0.036589 1.000000 -0.027588 0.131706 0.048440 0.084821 0.443723 -0.067086 0.089359
Niederösterreich 0.102649 -0.027588 1.000000 0.311861 0.119115 0.269426 0.066140 0.151841 0.289054
Oberösterreich 0.168406 0.131706 0.311861 1.000000 0.213567 0.294087 0.166632 0.135805 0.236075
Salzburg 0.138351 0.048440 0.119115 0.213567 1.000000 0.122491 0.091376 0.104751 0.123106
Steiermark 0.094062 0.084821 0.269426 0.294087 0.122491 1.000000 0.134024 0.105800 0.032831
Tirol 0.080794 0.443723 0.066140 0.166632 0.091376 0.134024 1.000000 0.063144 0.151319
Vorarlberg 0.032431 -0.067086 0.151841 0.135805 0.104751 0.105800 0.063144 1.000000 -0.004804
Wien 0.209089 0.089359 0.289054 0.236075 0.123106 0.032831 0.151319 -0.004804 1.000000